import datetime

from AutoTest05_06.utils.mysqlutil import MysqlUtil

mysqlutil = MysqlUtil()
class CaseUtil:
    def load_all_case(self,jwweb):
        sql = f'SELECT * FROM jwtest_case_list WHERE web="{jwweb}"'
        record = mysqlutil.get_fetchall(sql)
        return record

    def is_run_data(self,jwweb):
        # jw_run_list = []
        # all_case = self.load_all_case(jwweb)
        # for case in all_case:
        #     if case['isdel'] == 1:
        #         jw_run_list.append(case)
        # return jw_run_list
        return [case for case in self.load_all_case(jwweb) if case['isdel'] == 1]

    def loadConfkey(self,jwweb,jwkey):
        jwsql = f'SELECT * FROM jwtest_config WHERE web="{jwweb}" AND key1="{jwkey}"'
        return mysqlutil.get_fetchone(jwsql)

    def updateResults(self,response,is_pass,case_id): # response 实际结果，is_pass测试结果 case_id用例编号
        current_time = datetime.datetime.now().strftime('%Y_%m_%d %H_%M_%S')
        jwsql = f'INSERT INTO jwtest_result_record (case_id,times,response,result) VALUES("{case_id}","{current_time}","{response}","{is_pass}")'
        return mysqlutil.sql_execute(jwsql)
if __name__ == '__main__':
    case = CaseUtil()
    # print(case.load_all_case('okr-api'))
    # print(case.is_run_data('okr-api'))
    print(case.loadConfkey('atstudy_okr', 'url_api')['value'])
    # jia_caseId = '123'
    # jia_response = {'success':True,'message':'登录成功'}
    # jia_pass = True
    # print(case.updateResults(jia_response, jia_pass, jia_caseId))